package com.iptv.grape.domain;

import com.iptv.grape.util.AppLog;

import java.util.List;
import java.util.Objects;

// 播放进度
public class PlayProgress {
    // 资产ID
    private String assetID;
    // 播放地址
    private String playUrl;
    // 播放地址的剧集的ID
    private String subAssetID;
    // 最后一次播放进度
    private int lastPlayTime;


    public PlayProgress(){

    }



    public int getLastPlayTime() {
        return lastPlayTime;
    }

    public void setLastPlayTime(int lastPlayTime) {
        this.lastPlayTime = lastPlayTime;
    }

    public String getAssetID() {
        return assetID;
    }

    public void setAssetID(String assetID) {
        this.assetID = assetID;
    }

    public String getPlayUrl() {
        return playUrl;
    }

    public void setPlayUrl(String playUrl) {
        this.playUrl = playUrl;
    }

    public String getSubAssetID() {
        return subAssetID;
    }

    public void setSubAssetID(String subAssetID) {
        this.subAssetID = subAssetID;
    }

    public static PlayProgress find(List<PlayProgress> playProgressList,
                                    String subAssetID){
        try {
            if(playProgressList == null){
                //AppLog.getCurLog().out("PlayProgress.find 空集合");
                return null;
            }

            for (int i = 0; i < playProgressList.size(); i++) {
                PlayProgress playProgress = playProgressList.get(i);

                if (playProgress.getSubAssetID().equals(subAssetID)) {
                    //playProgress.setPlayUrl(playUrl);
                    //playProgress.setLastPlayTime(lastPlayTime);
                    return playProgress;
                }
            }
            return null;
        }
        catch (Exception e){
            //AppLog.getCurLog().out("PlayProgress.find" + e.getMessage());
            return null;
        }
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        PlayProgress that = (PlayProgress) o;
        return assetID.equals(that.assetID);
    }

    @Override
    public int hashCode() {
        return Objects.hash(assetID);
    }
}
